﻿using System.ComponentModel;
using System.Configuration;
using System.Configuration.Install;
using System.ServiceProcess;
using StockholmsStad.WindowsService.Properties;

namespace StockholmsStad.WindowsService
{
    /// <summary>
    /// Projektinstallationsklass som tillåter tjänsten att installeras som window tjänst.
    /// </summary>
    [RunInstaller(true)]
    public class ProjectInstaller : Installer
    {
        private readonly ServiceProcessInstaller process;
        private readonly ServiceInstaller service;

        /// <summary>
        /// Default konstruktor.
        /// </summary>
        public ProjectInstaller()
        {
            process = new ServiceProcessInstaller {Account = ServiceAccount.LocalSystem};
            //service = new ServiceInstaller { ServiceName = Resources.ServiceName, Description = Resources.ServiceDescription, StartType = ServiceStartMode.Automatic };
            // Ändrat till AppSettings så att vi kan styra i app.config vilka värden som gäller
            var serviceName = ConfigurationManager.AppSettings["ServiceName"] ?? Resources.ServiceName;
            var serviceDesc = ConfigurationManager.AppSettings["ServiceDescription"] ?? Resources.ServiceDescription;
            service = new ServiceInstaller { ServiceName = serviceName, Description = serviceDesc, StartType = ServiceStartMode.Automatic };

            Installers.Add(process);
            Installers.Add(service);
        }
    }
}
